package com.atguigu.day04;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Flink03_Transfrom_Union {
    public static void main(String[] args) throws Exception {
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        //2.从端口读取数据
        DataStreamSource<String> streamSource999 = env.socketTextStream("localhost", 9999);

        DataStreamSource<String> streamSource888 = env.socketTextStream("localhost", 8888);

        //TODO 使用union合并两条流
        DataStream<String> dataStream = streamSource999.union(streamSource888);

        SingleOutputStreamOperator<String> result = dataStream.map(new MapFunction<String, String>() {
            @Override
            public String map(String value) throws Exception {
                return "合并：" + value;
            }
        });

        result.print();

        env.execute();

    }
}
